package com.ac.scum.log.web.model.login.controller;

import com.ac.common.core.exception.BaseException;
import com.ac.common.core.result.Result;
import com.ac.scum.log.web.dto.login.LoginDTO;
import com.ac.scum.log.web.model.login.service.LoginService;
import com.ac.scum.log.web.model.login.vo.LoginVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 登录
 */
@RestController
@AllArgsConstructor
@RequestMapping("auth")
public class AuthController {

    private final LoginService loginService;

    @PostMapping("phoneLogin")
    public Result<LoginDTO> login(@RequestBody LoginVO loginVO) throws BaseException {
        return Result.ok(loginService.login(loginVO.getPhone(), loginVO.getPassword(), Boolean.FALSE));
    }

    @PostMapping("client/phoneLogin")
    public Result<LoginDTO> clientPhoneLogin(@RequestBody LoginVO loginVO) throws BaseException {
        return Result.ok(loginService.login(loginVO.getPhone(), loginVO.getPassword(), Boolean.TRUE));
    }

    @GetMapping("logout")
    public Result<Boolean> logout() throws BaseException {
        return Result.ok(loginService.logout());
    }
}
